load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_test")
load("//bazel:libarchive_test.bzl", "libarchive_test")

libarchive_test(name = "test_acl_nfs4", deps = [":lib"])
libarchive_test(name = "test_acl_pax", deps = [":lib"], tests = ["test_acl_pax_posix1e", "test_acl_pax_nfs4"])
libarchive_test(name = "test_acl_platform_nfs4", deps = [":lib"])
libarchive_test(
    name = "test_acl_platform_posix1e",
    deps = [":lib"],
    tests = [
        "test_acl_platform_posix1e_restore",
        "test_acl_platform_posix1e_read",
    ],
)
libarchive_test(name = "test_acl_posix1e", deps = [":lib"])
libarchive_test(
    name = "test_acl_text",
    deps = [":lib"],
    tests = [
        "test_acl_to_text",
        "test_acl_from_text",
    ],
)
libarchive_test(name = "test_archive_api_feature", deps = [":lib"])
libarchive_test(name = "test_archive_clear_error", deps = [":lib"])
libarchive_test(name = "test_archive_cmdline", deps = [":lib"])

libarchive_test(
    name = "test_archive_digest",
    deps = [":lib"],
    tests = [
        "test_archive_md5",
        "test_archive_rmd160",
        "test_archive_sha1",
        "test_archive_sha256",
        "test_archive_sha384",
        "test_archive_sha512",
    ],
)
libarchive_test(name = "test_archive_match_owner", deps = [":lib"])
libarchive_test(name = "test_archive_match_path", deps = [":lib"])
libarchive_test(name = "test_archive_match_time", deps = [":lib"])
libarchive_test(name = "test_archive_pathmatch", deps = [":lib"])
libarchive_test(
    name = "test_archive_read_add_passphrase",
    deps = [":lib"],
    tests = [
        "test_archive_read_add_passphrase",
        "test_archive_read_add_passphrase_incorrect_sequance",
        "test_archive_read_add_passphrase_single",
        "test_archive_read_add_passphrase_multiple",
        "test_archive_read_add_passphrase_set_callback1",
        "test_archive_read_add_passphrase_set_callback2",
        "test_archive_read_add_passphrase_set_callback3",
        "test_archive_read_add_passphrase_multiple_with_callback",
        "test_archive_read_add_passphrase_multiple_with_callback2",
    ],
)
libarchive_test(name = "test_archive_read_close_twice", deps = [":lib"])
libarchive_test(name = "test_archive_read_close_twice_open_fd", deps = [":lib"])
libarchive_test(name = "test_archive_read_close_twice_open_filename", deps = [":lib"])
libarchive_test(name = "test_archive_read_multiple_data_objects", deps = [":lib"])
libarchive_test(name = "test_archive_read_next_header_empty", deps = [":lib"])
libarchive_test(name = "test_archive_read_next_header_raw", deps = [":lib"])
libarchive_test(name = "test_archive_read_open2", deps = [":lib"])
libarchive_test(name = "test_archive_read_set_filter_option", deps = [":lib"])
libarchive_test(name = "test_archive_read_set_format_option", deps = [":lib"])
libarchive_test(name = "test_archive_read_set_option", deps = [":lib"])
libarchive_test(name = "test_archive_read_set_options", deps = [":lib"])
libarchive_test(name = "test_archive_read_support", deps = [":lib"])
libarchive_test(name = "test_archive_set_error", deps = [":lib"])
libarchive_test(
    name = "test_archive_string",
    deps = [":lib"],
    tests = [
        "test_archive_string",
        "test_archive_string_sort",
    ],
)
libarchive_test(name = "test_archive_string_conversion", deps = [":lib"])
libarchive_test(
    name = "test_archive_write_add_filter_by_name",
    deps = [":lib"],
    tests = [
        "test_archive_write_add_filter_by_name_b64encode",
        "test_archive_write_add_filter_by_name_bzip2",
        "test_archive_write_add_filter_by_name_compress",
        "test_archive_write_add_filter_by_name_grzip",
        "test_archive_write_add_filter_by_name_gzip",
        "test_archive_write_add_filter_by_name_lrzip",
        "test_archive_write_add_filter_by_name_lz4",
        "test_archive_write_add_filter_by_name_lzip",
        "test_archive_write_add_filter_by_name_lzma",
        "test_archive_write_add_filter_by_name_lzop",
        "test_archive_write_add_filter_by_name_uuencode",
        "test_archive_write_add_filter_by_name_xz",
        "test_archive_write_add_filter_by_name_zstd",
    ],
)
libarchive_test(name = "test_archive_write_set_filter_option", deps = [":lib"])
libarchive_test(
    name = "test_archive_write_set_format_by_name",
    deps = [":lib"],
    tests = [
        "test_archive_write_set_format_by_name_7zip",
        "test_archive_write_set_format_by_name_ar",
        "test_archive_write_set_format_by_name_arbsd",
        "test_archive_write_set_format_by_name_arsvr4",
        "test_archive_write_set_format_by_name_bsdtar",
        "test_archive_write_set_format_by_name_cd9660",
        "test_archive_write_set_format_by_name_cpio",
        "test_archive_write_set_format_by_name_gnutar",
        "test_archive_write_set_format_by_name_iso",
        "test_archive_write_set_format_by_name_iso9660",
        "test_archive_write_set_format_by_name_mtree",
        "test_archive_write_set_format_by_name_mtree_classic",
        "test_archive_write_set_format_by_name_newc",
        "test_archive_write_set_format_by_name_odc",
        "test_archive_write_set_format_by_name_oldtar",
        "test_archive_write_set_format_by_name_pax",
        "test_archive_write_set_format_by_name_paxr",
        "test_archive_write_set_format_by_name_posix",
        "test_archive_write_set_format_by_name_rpax",
        "test_archive_write_set_format_by_name_shar",
        "test_archive_write_set_format_by_name_shardump",
        "test_archive_write_set_format_by_name_ustar",
        "test_archive_write_set_format_by_name_v7tar",
        "test_archive_write_set_format_by_name_v7",
        "test_archive_write_set_format_by_name_warc",
        "test_archive_write_set_format_by_name_xar",
        "test_archive_write_set_format_by_name_zip",
    ],
)
libarchive_test(
    name = "test_archive_write_set_format_filter_by_ext",
    deps = [":lib"],
    tests = [
        "test_archive_write_set_format_filter_by_ext_7zip",
        "test_archive_write_set_format_filter_by_ext_zip",
        "test_archive_write_set_format_filter_by_ext_jar",
        "test_archive_write_set_format_filter_by_ext_a",
        "test_archive_write_set_format_filter_by_ext_ar",
        "test_archive_write_set_format_filter_by_ext_cpio",
        "test_archive_write_set_format_filter_by_ext_iso",
        "test_archive_write_set_format_filter_by_ext_tar",
        "test_archive_write_set_format_filter_by_ext_tar_gz",
        "test_archive_write_set_format_filter_by_ext_tar_bz2",
        "test_archive_write_set_format_filter_by_ext_tar_xz",
        "test_archive_write_set_format_filter_by_no_ext_def_zip",
        "test_archive_write_set_format_filter_by_ext_tar_bz2_def_zip",
    ],
)
libarchive_test(name = "test_archive_write_set_format_option", deps = [":lib"])
libarchive_test(name = "test_archive_write_set_option", deps = [":lib"])
libarchive_test(name = "test_archive_write_set_options", deps = [":lib"])
libarchive_test(
    name = "test_archive_write_set_passphrase",
    deps = [":lib"],
    tests = [
        "test_archive_write_set_passphrase",
        "test_archive_write_set_passphrase_callback",
    ],
)
libarchive_test(name = "test_bad_fd", deps = [":lib"])
libarchive_test(name = "test_compat_bzip2", deps = [":lib"])
libarchive_test(name = "test_compat_cpio", deps = [":lib"])
libarchive_test(name = "test_compat_gtar", deps = [":lib"])
libarchive_test(name = "test_compat_gzip", deps = [":lib"])
libarchive_test(name = "test_compat_lz4", deps = [":lib"])
libarchive_test(name = "test_compat_lzip", deps = [":lib"])
libarchive_test(name = "test_compat_lzma", deps = [":lib"])
libarchive_test(name = "test_compat_lzop", deps = [":lib"])
libarchive_test(name = "test_compat_mac", deps = [":lib"])
libarchive_test(name = "test_compat_perl_archive_tar", deps = [":lib"])
libarchive_test(name = "test_compat_plexus_archiver_tar", deps = [":lib"])
libarchive_test(name = "test_compat_solaris_pax_sparse", deps = [":lib"])
libarchive_test(name = "test_compat_solaris_tar_acl", deps = [":lib"])
libarchive_test(
    name = "test_compat_star_acl",
    deps = [":lib"],
    tests = [
        "test_compat_star_acl_posix1e",
        "test_compat_star_acl_nfs4",
    ],
)
libarchive_test(name = "test_compat_tar_directory", deps = [":lib"])
libarchive_test(name = "test_compat_tar_hardlink", deps = [":lib"])
libarchive_test(name = "test_compat_uudecode", deps = [":lib"])
libarchive_test(name = "test_compat_uudecode_large", deps = [":lib"])
libarchive_test(name = "test_compat_xz", deps = [":lib"])

libarchive_test(
    name = "test_compat_zip",
    deps = [":lib"],
    tests = [
        "test_compat_zip_1",
        "test_compat_zip_2",
        "test_compat_zip_3",
        "test_compat_zip_4",
        "test_compat_zip_5",
        "test_compat_zip_6",
        "test_compat_zip_7",
        "test_compat_zip_8",
    ],
)
libarchive_test(name = "test_compat_zstd", deps = [":lib"])
libarchive_test(name = "test_empty_write", deps = [":lib"])
libarchive_test(name = "test_entry", deps = [":lib"])
libarchive_test(name = "test_entry_strmode", deps = [":lib"])
libarchive_test(name = "test_extattr_freebsd", deps = [":lib"])
libarchive_test(name = "test_filter_count", deps = [":lib"])
libarchive_test(
    name = "test_fuzz",
    size = "large",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip", "manual"],  # NOTE: runs too slow on Windows
    tests = [
        "test_fuzz_ar",
        "test_fuzz_cab",
        "test_fuzz_cpio",
        "test_fuzz_iso9660",
        "test_fuzz_lzh",
        "test_fuzz_mtree",
        "test_fuzz_rar",
        "test_fuzz_tar",
        "test_fuzz_zip",
    ],
)
libarchive_test(
    name = "test_gnutar_filename_encoding",
    deps = [":lib"],
    tests = [
        "test_gnutar_filename_encoding_UTF8_CP866",
        "test_gnutar_filename_encoding_KOI8R_UTF8",
        "test_gnutar_filename_encoding_KOI8R_CP866",
        "test_gnutar_filename_encoding_CP1251_UTF8",
        "test_gnutar_filename_encoding_ru_RU_CP1251",
        "test_gnutar_filename_encoding_Russian_Russia",
        "test_gnutar_filename_encoding_EUCJP_UTF8",
        "test_gnutar_filename_encoding_EUCJP_CP932",
    ],
)
libarchive_test(name = "test_link_resolver", deps = [":lib"])
libarchive_test(name = "test_open_failure", deps = [":lib"])
libarchive_test(name = "test_open_fd", deps = [":lib"])
libarchive_test(name = "test_open_file", deps = [":lib"])
libarchive_test(name = "test_open_filename", deps = [":lib"])
libarchive_test(
    name = "test_pax_filename_encoding",
    deps = [":lib"],
    tests = [
        "test_pax_filename_encoding_KOI8R",
        "test_pax_filename_encoding_CP1251",
        "test_pax_filename_encoding_EUCJP",
        "test_pax_filename_encoding_CP932",
        "test_pax_filename_encoding_KOI8R_BINARY",
        "test_pax_filename_encoding_KOI8R_CP1251",
        "test_pax_filename_encoding",
    ],
)
libarchive_test(name = "test_pax_xattr_header", deps = [":lib"])
libarchive_test(name = "test_read_data_large", deps = [":lib"])
libarchive_test(name = "test_read_disk", deps = [":lib"])
libarchive_test(name = "test_read_disk_directory_traversals", deps = [":lib"])
libarchive_test(name = "test_read_disk_entry_from_file", deps = [":lib"])
libarchive_test(name = "test_read_extract", deps = [":lib"])
libarchive_test(name = "test_read_file_nonexistent", deps = [":lib"])
libarchive_test(
    name = "test_read_filter_compress",
    deps = [":lib"],
    tests = [
        "test_read_filter_compress_truncated",
        "test_read_filter_compress_empty2",
        "test_read_filter_compress_invalid",
    ],
)
libarchive_test(name = "test_read_filter_grzip", deps = [":lib"])
libarchive_test(name = "test_read_filter_lrzip", deps = [":lib"])
libarchive_test(name = "test_read_filter_lzop", deps = [":lib"])
libarchive_test(name = "test_read_filter_lzop_multiple_parts", deps = [":lib"])
libarchive_test(name = "test_read_filter_program", deps = [":lib"])
libarchive_test(name = "test_read_filter_program_signature", deps = [":lib"])
libarchive_test(
    name = "test_read_filter_uudecode",
    deps = [":lib"],
    tests = [
        "test_read_filter_uudecode",
        "test_read_filter_uudecode_base64",
    ],
)
libarchive_test(
    name = "test_read_filter_uudecode_raw",
    deps = [":lib"],
    tests = [
        "test_read_filter_uudecode_raw",
        "test_read_filter_uudecode_base64_raw",
    ],
)
libarchive_test(
    name = "test_read_format_7zip",
    deps = [":lib"],
    tests = [
        "test_read_format_7zip",
        "test_read_format_7zip_bzip2",
        "test_read_format_7zip_from_fd",
        "test_read_format_7zip_copy",
        "test_read_format_7zip_deflate",
        "test_read_format_7zip_zstd",
        "test_read_format_7zip_zstd_solid",
        "test_read_format_7zip_zstd_bcj",
        "test_read_format_7zip_zstd_nobcj",
        "test_read_format_7zip_empty",
        "test_read_format_7zip_lzma1",
        "test_read_format_7zip_lzma2",
        "test_read_format_7zip_zstd_arm",
        "test_read_format_7zip_lzma2_arm",
        "test_read_format_7zip_ppmd",
        "test_read_format_7zip_lzma2_arm64",
        "test_read_format_7zip_deflate_arm64",
        "test_read_format_7zip_win_attrib",
    ],
    target_compatible_with = select({
        # TODO(zaucy?): make it pass on windows
        "@platforms//os:windows": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)
libarchive_test(name = "test_read_format_7zip_encryption_data", deps = [":lib"])
libarchive_test(name = "test_read_format_7zip_encryption_header", deps = [":lib"])
libarchive_test(name = "test_read_format_7zip_encryption_partially", deps = [":lib"])
libarchive_test(name = "test_read_format_7zip_malformed", deps = [":lib"])
libarchive_test(name = "test_read_format_7zip_packinfo_digests", deps = [":lib"])
libarchive_test(name = "test_read_format_ar", deps = [":lib"])
libarchive_test(name = "test_read_format_cab", deps = [":lib"])
libarchive_test(name = "test_read_format_cab_filename", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_afio", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_Z", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_be", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_bz2", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_gz", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_le", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_lzip", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_lzma", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_bin_xz", deps = [":lib"])
libarchive_test(
    name = "test_read_format_cpio_filename",
    deps = [":lib"],
    tests = [
        "test_read_format_cpio_filename_eucJP_UTF8",
        "test_read_format_cpio_filename_UTF8_eucJP",
        "test_read_format_cpio_filename_UTF8_UTF8_jp",
        "test_read_format_cpio_filename_CP866_KOI8R",
        "test_read_format_cpio_filename_CP866_UTF8",
        "test_read_format_cpio_filename_KOI8R_CP866",
        "test_read_format_cpio_filename_KOI8R_UTF8",
        "test_read_format_cpio_filename_UTF8_KOI8R",
        "test_read_format_cpio_filename_UTF8_CP866",
        "test_read_format_cpio_filename_UTF8_UTF8_ru",
        "test_read_format_cpio_filename_eucJP_CP932",
        "test_read_format_cpio_filename_UTF8_CP932",
        "test_read_format_cpio_filename_CP866_CP1251",
        "test_read_format_cpio_filename_CP866_CP1251_win",
        "test_read_format_cpio_filename_KOI8R_CP1251",
        "test_read_format_cpio_filename_UTF8_CP1251",
    ],
)
libarchive_test(name = "test_read_format_cpio_odc", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_svr4_bzip2_rpm", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_svr4_gzip", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_svr4_gzip_rpm", deps = [":lib"])
libarchive_test(name = "test_read_format_cpio_svr4c_Z", deps = [":lib"])
libarchive_test(name = "test_read_format_empty", deps = [":lib"])
libarchive_test(
    name = "test_read_format_gtar_filename",
    deps = [":lib"],
    tests = [
        "test_read_format_gtar_filename_eucJP_UTF8",
        "test_read_format_gtar_filename_CP866_KOI8R",
        "test_read_format_gtar_filename_CP866_UTF8",
        "test_read_format_gtar_filename_KOI8R_CP866",
        "test_read_format_gtar_filename_KOI8R_UTF8",
        "test_read_format_gtar_filename_eucJP_CP932",
        "test_read_format_gtar_filename_CP866_CP1251",
        "test_read_format_gtar_filename_CP866_CP1251_win",
    ],
)
libarchive_test(name = "test_read_format_gtar_gz", deps = [":lib"])
libarchive_test(name = "test_read_format_gtar_lzma", deps = [":lib"])
libarchive_test(name = "test_read_format_gtar_sparse", deps = [":lib"])
libarchive_test(name = "test_read_format_gtar_sparse_skip_entry", deps = [":lib"])
libarchive_test(name = "test_read_format_iso_Z", deps = [":lib"])
libarchive_test(name = "test_read_format_iso_multi_extent", deps = [":lib"])
libarchive_test(name = "test_read_format_iso_xorriso", deps = [":lib"])
libarchive_test(name = "test_read_format_isojoliet_bz2", deps = [":lib"])
libarchive_test(name = "test_read_format_isojoliet_long", deps = [":lib"])
libarchive_test(name = "test_read_format_isojoliet_rr", deps = [":lib"])
libarchive_test(name = "test_read_format_isojoliet_versioned", deps = [":lib"])
libarchive_test(name = "test_read_format_isorr_bz2", deps = [":lib"])
libarchive_test(name = "test_read_format_isorr_ce", deps = [":lib"])
libarchive_test(name = "test_read_format_isorr_new_bz2", deps = [":lib"])
libarchive_test(name = "test_read_format_isorr_rr_moved", deps = [":lib"])
libarchive_test(name = "test_read_format_isozisofs_bz2", deps = [":lib"])
libarchive_test(name = "test_read_format_lha", deps = [":lib"])
libarchive_test(name = "test_read_format_lha_bugfix_0", deps = [":lib"])
libarchive_test(name = "test_read_format_lha_filename", deps = [":lib"])
libarchive_test(
    name = "test_read_format_lha_filename_utf16",
    deps = [":lib"],
    tests = [
        "test_read_format_lha_filename_UTF16",
    ],
)
libarchive_test(name = "test_read_format_mtree", deps = [":lib"])
libarchive_test(name = "test_read_format_mtree_crash747", deps = [":lib"])
libarchive_test(name = "test_read_format_pax_bz2", deps = [":lib"])
libarchive_test(
    name = "test_read_format_rar",
    deps = [":lib"],
    tests = [
        "test_read_format_rar_set_format",
        "test_read_format_rar_basic",
        "test_read_format_rar_subblock",
        "test_read_format_rar_noeof",
        "test_read_format_rar_unicode_UTF8",
        "test_read_format_rar_unicode_CP932",
        "test_read_format_rar_compress_normal",
        "test_read_format_rar_multi_lzss_blocks",
        "test_read_format_rar_compress_best",
        "test_read_format_rar_ppmd_lzss_conversion",
        "test_read_format_rar_binary",
        "test_read_format_rar_windows",
        "test_read_format_rar_multivolume",
        "test_read_format_rar_multivolume_w",
        "test_read_format_rar_multivolume_skip",
        "test_read_format_rar_sfx",
        "test_read_format_rar_multivolume_stored_file",
        "test_read_format_rar_multivolume_stored_file_skip",
        "test_read_format_rar_multivolume_seek_data",
        "test_read_format_rar_multivolume_seek_multiple_files",
        "test_read_format_rar_multivolume_uncompressed_files",
        "test_read_format_rar_ppmd_use_after_free",
        "test_read_format_rar_ppmd_use_after_free2",
    ],
)
libarchive_test(
    name = "test_read_format_rar5",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on Windows
    tests = [
        "test_read_format_rar5_set_format",
        "test_read_format_rar5_stored",
        "test_read_format_rar5_compressed",
        "test_read_format_rar5_multiple_files",
        "test_read_format_rar5_multiple_files_solid",
        "test_read_format_rar5_multiarchive_skip_all",
        "test_read_format_rar5_multiarchive_skip_all_but_first",
        "test_read_format_rar5_multiarchive_skip_all_but_second",
        "test_read_format_rar5_blake2",
        "test_read_format_rar5_arm_filter",
        "test_read_format_rar5_stored_skip_all",
        "test_read_format_rar5_stored_skip_in_part",
        "test_read_format_rar5_stored_skip_all_but_first",
        "test_read_format_rar5_stored_skip_all_in_part",
        "test_read_format_rar5_multiarchive_solid_extr_all",
        "test_read_format_rar5_multiarchive_solid_skip_all",
        "test_read_format_rar5_multiarchive_solid_skip_all_but_first",
        "test_read_format_rar5_multiarchive_solid_skip_all_but_scnd",
        "test_read_format_rar5_multiarchive_solid_skip_all_but_third",
        "test_read_format_rar5_multiarchive_solid_skip_all_but_last",
        "test_read_format_rar5_solid_skip_all",
        "test_read_format_rar5_solid_skip_all_but_first",
        "test_read_format_rar5_solid_skip_all_but_second",
        "test_read_format_rar5_solid_skip_all_but_last",
        "test_read_format_rar5_extract_win32",
        "test_read_format_rar5_unicode",
        "test_read_format_rar5_block_by_block",
        "test_read_format_rar5_owner",
        "test_read_format_rar5_symlink",
        "test_read_format_rar5_hardlink",
        "test_read_format_rar5_extra_field_version",
        "test_read_format_rar5_readtables_overflow",
        "test_read_format_rar5_leftshift1",
        "test_read_format_rar5_leftshift2",
        "test_read_format_rar5_truncated_huff",
        "test_read_format_rar5_invalid_dict_reference",
        "test_read_format_rar5_distance_overflow",
        "test_read_format_rar5_nonempty_dir_stream",
        "test_read_format_rar5_fileattr",
        "test_read_format_rar5_different_window_size",
        "test_read_format_rar5_window_buf_and_size_desync",
        "test_read_format_rar5_arm_filter_on_window_boundary",
        "test_read_format_rar5_different_solid_window_size",
        "test_read_format_rar5_different_winsize_on_merge",
        "test_read_format_rar5_block_size_is_too_small",
        "test_read_format_rar5_sfx",
        "test_read_format_rar5_decode_number_out_of_bounds_read",
        "test_read_format_rar5_bad_window_size_in_multiarchive_file",
        "test_read_format_rar5_read_data_block_uninitialized_offset",
    ],
)
libarchive_test(name = "test_read_format_rar_encryption_data", deps = [":lib"])
libarchive_test(name = "test_read_format_rar_encryption_header", deps = [":lib"])
libarchive_test(name = "test_read_format_rar_encryption_partially", deps = [":lib"])
libarchive_test(name = "test_read_format_rar_filter", deps = [":lib"])
libarchive_test(name = "test_read_format_rar_invalid1", deps = [":lib"])
libarchive_test(name = "test_read_format_raw", deps = [":lib"])
libarchive_test(name = "test_read_format_tar", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_concatenated", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_empty_filename", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_empty_pax", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_empty_with_gnulabel", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_filename", deps = [":lib"])
libarchive_test(name = "test_read_format_tar_invalid_pax_size", deps = [":lib"])
libarchive_test(name = "test_read_format_tbz", deps = [":lib"])
libarchive_test(name = "test_read_format_tgz", deps = [":lib"])
libarchive_test(name = "test_read_format_tlz", deps = [":lib"])
libarchive_test(name = "test_read_format_txz", deps = [":lib"])
libarchive_test(name = "test_read_format_tz", deps = [":lib"])
libarchive_test(name = "test_read_format_ustar_filename", deps = [":lib"])
libarchive_test(name = "test_read_format_warc", deps = [":lib"])
libarchive_test(name = "test_read_format_xar", deps = [":lib"])
libarchive_test(
    name = "test_read_format_zip",
    deps = [":lib"],
    tests = [
        # "test_read_format_zip", # TODO(zaucy): figure out why this is failing since 3.8.0
        "test_read_format_zip_ppmd_one_file",
        "test_read_format_zip_ppmd_one_file_blockread",
        "test_read_format_zip_ppmd_multi",
        "test_read_format_zip_ppmd_multi_blockread",
        "test_read_format_zip_lzma_one_file",
        "test_read_format_zip_lzma_one_file_blockread",
        "test_read_format_zip_lzma_multi",
        "test_read_format_zip_lzma_multi_blockread",
        "test_read_format_zip_bzip2_one_file",
        "test_read_format_zip_bzip2_one_file_blockread",
        "test_read_format_zip_bzip2_multi",
        "test_read_format_zip_bzip2_multi_blockread",
        "test_read_format_zip_zstd_one_file",
        "test_read_format_zip_zstd_one_file_blockread",
        "test_read_format_zip_zstd_multi",
        "test_read_format_zip_zstd_multi_blockread",
        "test_read_format_zip_xz_multi",
        "test_read_format_zip_xz_multi_blockread",
        "test_read_format_zip_ppmd8_crash_1",
        "test_read_format_zip_bz2_hang_on_invalid",
        "test_read_format_zip_ppmd8_crash_2",
        "test_read_format_zip_lzma_alone_leak",
        "test_read_format_zip_lzma_stream_end",
        "test_read_format_zip_lzma_stream_end_blockread",
        "test_read_format_zip_7z_lzma",
        # "test_read_format_zip_7z_deflate", # TODO(zaucy): figure out why this is failing since 3.8.0
    ],
)
libarchive_test(
    name = "test_read_format_zip_7075_utf8_paths",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_utf8_paths",
    ],
)
libarchive_test(name = "test_read_format_zip_comment_stored", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_encryption_data", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_encryption_header", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_encryption_partially", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_extra_padding", deps = [":lib"])
libarchive_test(
    name = "test_read_format_zip_filename",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_filename_CP932_eucJP",
        "test_read_format_zip_filename_CP932_UTF8",
        "test_read_format_zip_filename_UTF8_eucJP",
        "test_read_format_zip_filename_UTF8_UTF8",
        "test_read_format_zip_filename_CP866_KOI8R",
        "test_read_format_zip_filename_CP866_UTF8",
        "test_read_format_zip_filename_KOI8R_CP866",
        "test_read_format_zip_filename_KOI8R_UTF8",
        "test_read_format_zip_filename_UTF8_KOI8R",
        "test_read_format_zip_filename_UTF8_CP866",
        "test_read_format_zip_filename_UTF8_UTF8_ru",
        "test_read_format_zip_filename_CP932_CP932",
        "test_read_format_zip_filename_UTF8_CP932",
        "test_read_format_zip_filename_CP866_CP1251",
        "test_read_format_zip_filename_CP866_CP1251_win",
        "test_read_format_zip_filename_KOI8R_CP1251",
        "test_read_format_zip_filename_UTF8_CP1251",
        "test_read_format_zip_filename_KOI8R_UTF8_2",
    ],
)
libarchive_test(
    name = "test_read_format_zip_high_compression",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_high_compression",
        "test_read_format_zip_high_compression2",
    ],
)
libarchive_test(name = "test_read_format_zip_jar", deps = [":lib"])
# libarchive_test(name = "test_read_format_zip_mac_metadata", deps = [":lib"]) # TODO(zaucy): figure out why this is failing since 3.8.0
libarchive_test(name = "test_read_format_zip_malformed", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_msdos", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_nested", deps = [":lib"])
libarchive_test(name = "test_read_format_zip_nofiletype", deps = [":lib"])
libarchive_test(
    name = "test_read_format_zip_padded",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_padded1",
        "test_read_format_zip_padded2",
        "test_read_format_zip_padded3",
    ],
)
libarchive_test(name = "test_read_format_zip_sfx", deps = [":lib"])
# libarchive_test(name = "test_read_format_zip_traditional_encryption_data", deps = [":lib"]) # TODO(zaucy): figure out why this is failing since 3.8.0
libarchive_test(
    name = "test_read_format_zip_winzip_aes",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_winzip_aes128",
        "test_read_format_zip_winzip_aes256",
        "test_read_format_zip_winzip_aes256_stored",
    ],
    tags = ["bcr_presubmit_skip"],  # TODO: failing
)
libarchive_test(
    name = "test_read_format_zip_winzip_aes_large",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_winzip_aes256_large",
    ],
    tags = ["bcr_presubmit_skip"],  # TODO: failing
)
libarchive_test(name = "test_read_format_zip_with_invalid_traditional_eocd", deps = [":lib"])
libarchive_test(
    name = "test_read_format_zip_zip64",
    deps = [":lib"],
    tests = [
        "test_read_format_zip_zip64a",
        "test_read_format_zip_zip64b",
    ],
)
libarchive_test(name = "test_read_large", deps = [":lib"])
libarchive_test(name = "test_read_pax_truncated", deps = [":lib"])
libarchive_test(name = "test_read_pax_xattr_rht_security_selinux", deps = [":lib"])
libarchive_test(name = "test_read_pax_xattr_schily", deps = [":lib"])
libarchive_test(name = "test_read_position", deps = [":lib"])
libarchive_test(
    name = "test_read_set_format",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on Windows
    tests = [
        "test_read_set_format",
        "test_read_set_wrong_format",
        "test_read_append_filter",
        "test_read_append_wrong_filter",
        "test_read_append_filter_program",
        "test_read_append_filter_wrong_program",
    ],
)
libarchive_test(name = "test_read_too_many_filters", deps = [":lib"])
libarchive_test(name = "test_read_truncated", deps = [":lib"])
libarchive_test(
    name = "test_read_truncated_filter",
    deps = [":lib"],
    tests = [
        "test_read_truncated_filter_bzip2",
        "test_read_truncated_filter_compress",
        "test_read_truncated_filter_gzip",
        "test_read_truncated_filter_lzip",
        "test_read_truncated_filter_lzma",
        "test_read_truncated_filter_lzop",
        "test_read_truncated_filter_xz",
    ],
)
libarchive_test(name = "test_short_writes", deps = [":lib"])
libarchive_test(
    name = "test_sparse_basic",
    deps = [":lib"],
    tests = [
        # TODO: tests_sparse_basic not passing on macOS
        # "test_sparse_basic",
        "test_fully_sparse_files",
    ],
)
libarchive_test(name = "test_tar_filenames", deps = [":lib"])
libarchive_test(name = "test_tar_large", deps = [":lib"])
libarchive_test(
    name = "test_ustar_filename_encoding",
    deps = [":lib"],
    tests = [
        "test_ustar_filename_encoding_UTF8_CP866",
        "test_ustar_filename_encoding_KOI8R_UTF8",
        "test_ustar_filename_encoding_KOI8R_CP866",
        "test_ustar_filename_encoding_CP1251_UTF8",
        "test_ustar_filename_encoding_ru_RU_CP1251",
        "test_ustar_filename_encoding_Russian_Russia",
        "test_ustar_filename_encoding_EUCJP_UTF8",
        "test_ustar_filename_encoding_EUCJP_CP932",
        "test_ustar_filename_encoding_CP932_UTF8",
    ],
)
libarchive_test(name = "test_ustar_filenames", deps = [":lib"])
libarchive_test(name = "test_warn_missing_hardlink_target", deps = [":lib"])
libarchive_test(name = "test_write_disk", deps = [":lib"])
libarchive_test(name = "test_write_disk_appledouble", deps = [":lib"])
libarchive_test(name = "test_write_disk_failures", deps = [":lib"])
libarchive_test(name = "test_write_disk_fixup", deps = [":lib"])
libarchive_test(name = "test_write_disk_hardlink", deps = [":lib"])
libarchive_test(name = "test_write_disk_hfs_compression", deps = [":lib"])
libarchive_test(name = "test_write_disk_lookup", deps = [":lib"])
libarchive_test(name = "test_write_disk_mac_metadata", deps = [":lib"])
libarchive_test(name = "test_write_disk_no_hfs_compression", deps = [":lib"])
libarchive_test(
    name = "test_write_disk_perms",
    deps = [":lib"],
    target_compatible_with = select({
        # TODO: not working on macos
        "@platforms//os:macos": ["@platforms//:incompatible"],
        "//conditions:default": [],
    }),
)
libarchive_test(name = "test_write_disk_secure", deps = [":lib"])
libarchive_test(name = "test_write_disk_secure744", deps = [":lib"])
libarchive_test(name = "test_write_disk_secure745", deps = [":lib"])
libarchive_test(
    name = "test_write_disk_secure746",
    deps = [":lib"],
    tests = [
        "test_write_disk_secure746a",
        "test_write_disk_secure746b",
    ],
)
libarchive_test(name = "test_write_disk_sparse", deps = [":lib"])
libarchive_test(name = "test_write_disk_symlink", deps = [":lib"])
libarchive_test(name = "test_write_disk_times", deps = [":lib"])
libarchive_test(name = "test_write_filter_b64encode", deps = [":lib"])
libarchive_test(name = "test_write_filter_bzip2", deps = [":lib"])
libarchive_test(name = "test_write_filter_compress", deps = [":lib"])
libarchive_test(name = "test_write_filter_gzip", deps = [":lib"])
libarchive_test(name = "test_write_filter_gzip_timestamp", deps = [":lib"])
libarchive_test(name = "test_write_filter_lrzip", deps = [":lib"])
libarchive_test(name = "test_write_filter_lz4", deps = [":lib"])
libarchive_test(name = "test_write_filter_lzip", deps = [":lib"])
libarchive_test(name = "test_write_filter_lzma", deps = [":lib"])
libarchive_test(name = "test_write_filter_lzop", deps = [":lib"])
libarchive_test(name = "test_write_filter_program", deps = [":lib"])
libarchive_test(name = "test_write_filter_uuencode", deps = [":lib"])
libarchive_test(name = "test_write_filter_xz", deps = [":lib"])
libarchive_test(name = "test_write_filter_zstd", deps = [":lib"])
libarchive_test(
    name = "test_write_format_7zip",
    deps = [":lib"],
    tests = [
        "test_write_format_7zip",
        "test_write_format_7zip_basic_bzip2",
        "test_write_format_7zip_basic_copy",
        "test_write_format_7zip_basic_deflate",
        "test_write_format_7zip_basic_lzma1",
        "test_write_format_7zip_basic_lzma2",
        "test_write_format_7zip_basic_ppmd",
    ],
)
libarchive_test(
    name = "test_write_format_7zip_empty",
    deps = [":lib"],
    tests = [
        "test_write_format_7zip_empty_archive",
        "test_write_format_7zip_empty_files",
    ],
)
libarchive_test(
    name = "test_write_format_7zip_large",
    deps = [":lib"],
    tests = [
        "test_write_format_7zip_large_bzip2",
        "test_write_format_7zip_large_copy",
        "test_write_format_7zip_large_deflate",
        "test_write_format_7zip_large_lzma1",
        "test_write_format_7zip_large_lzma2",
        "test_write_format_7zip_large_ppmd",
    ],
)
libarchive_test(name = "test_write_format_ar", deps = [":lib"])
libarchive_test(name = "test_write_format_cpio", deps = [":lib"])
libarchive_test(name = "test_write_format_cpio_empty", deps = [":lib"])
libarchive_test(name = "test_write_format_cpio_newc", deps = [":lib"])
libarchive_test(name = "test_write_format_cpio_odc", deps = [":lib"])
libarchive_test(name = "test_write_format_gnutar", deps = [":lib"])
libarchive_test(
    name = "test_write_format_gnutar_filenames",
    deps = [":lib"],
    tests = [
        "test_write_format_gnutar_filenames",
        "test_write_format_gnutar_linknames",
    ],
)
libarchive_test(
    name = "test_write_format_iso9660",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on macOS arm64
)
libarchive_test(
    name = "test_write_format_iso9660_boot",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on macOS arm64
)
libarchive_test(name = "test_write_format_iso9660_empty", deps = [":lib"])
libarchive_test(
    name = "test_write_format_iso9660_filename",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on macOS arm64
)
libarchive_test(
    name = "test_write_format_iso9660_zisofs",
    deps = [":lib"],
    tags = ["bcr_presubmit_skip"],  # TODO: failing on macOS arm64
)
libarchive_test(
    name = "test_write_format_mtree",
    deps = [":lib"],
    tests = [
        "test_write_format_mtree",
        "test_write_format_mtree_no_leading_dotslash",
    ],
)
libarchive_test(name = "test_write_format_mtree_absolute_path", deps = [":lib"])
libarchive_test(name = "test_write_format_mtree_classic", deps = [":lib"])
libarchive_test(name = "test_write_format_mtree_classic_indent", deps = [":lib"])
libarchive_test(name = "test_write_format_mtree_fflags", deps = [":lib"])
libarchive_test(name = "test_write_format_mtree_no_separator", deps = [":lib"])
libarchive_test(name = "test_write_format_mtree_quoted_filename", deps = [":lib"])
libarchive_test(name = "test_write_format_pax", deps = [":lib"])
libarchive_test(name = "test_write_format_raw", deps = [":lib"])
libarchive_test(name = "test_write_format_raw_b64", deps = [":lib"])
libarchive_test(name = "test_write_format_shar_empty", deps = [":lib"])
libarchive_test(name = "test_write_format_tar", deps = [":lib"])
libarchive_test(name = "test_write_format_tar_empty", deps = [":lib"])
libarchive_test(name = "test_write_format_tar_sparse", deps = [":lib"])
libarchive_test(name = "test_write_format_tar_ustar", deps = [":lib"])
libarchive_test(name = "test_write_format_tar_v7tar", deps = [":lib"])
libarchive_test(name = "test_write_format_warc", deps = [":lib"])
libarchive_test(name = "test_write_format_warc_empty", deps = [":lib"])
libarchive_test(name = "test_write_format_xar", deps = [":lib"])
libarchive_test(name = "test_write_format_xar_empty", deps = [":lib"])
libarchive_test(
    name = "test_write_format_zip",
    deps = [":lib"],
    tests = [
        "test_write_format_zip",
        "test_write_format_zip64",
        "test_write_format_zip_traditional_pkware_encryption",
        "test_write_format_zip_winzip_aes128_encryption",
        "test_write_format_zip_winzip_aes256_encryption",
    ],
)
libarchive_test(name = "test_write_format_zip64_stream", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_compression_store", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_empty", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_empty_zip64", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_entry_size_unset", deps = [":lib"], tests = ["test_write_format_zip_size_unset"])
libarchive_test(name = "test_write_format_zip_file", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_file_zip64", deps = [":lib"])
libarchive_test(name = "test_write_format_zip_large", deps = [":lib"])

# TODO: figure out why this test fails with Bazel
libarchive_test(name = "test_write_format_zip_stream", deps = [":lib"], tags = ["manual"])

libarchive_test(
    name = "test_write_format_zip_zip64",
    deps = [":lib"],
    tests = [
        "test_write_format_zip_zip64_oversize",
    ],
)
libarchive_test(name = "test_write_open_memory", deps = [":lib"])
libarchive_test(
    name = "test_write_read_format_zip",
    deps = [":lib"],
    tests = [
        "test_write_read_format_zip",
        "test_write_read_format_zip_improved_streaming",
        "test_write_read_format_zip64",
        "test_write_read_format_zip64_improved_streaming",
    ],
)
libarchive_test(name = "test_xattr_platform", deps = [":lib"])
libarchive_test(
    name = "test_zip_filename_encoding",
    deps = [":lib"],
    tests = [
        "test_zip_filename_encoding_UTF8",
        "test_zip_filename_encoding_KOI8R",
        "test_zip_filename_encoding_ru_RU_CP1251",
        "test_zip_filename_encoding_Russian_Russia",
        "test_zip_filename_encoding_EUCJP",
        "test_zip_filename_encoding_CP932",
    ],
)

cc_library(
    name = "lib",
    strip_include_prefix = ".",
    hdrs = ["test.h"],
    srcs = ["read_open_memory.c"],
    linkopts = select({
        # tests override some methods in libarchive
        # SEE: read_open_memory.c
        "@rules_cc//cc/compiler:msvc-cl": ["/IGNORE:4217"],
        "//conditions:default": [],
    }),
    deps = [
        "//:config",
        "//test_utils:common",
    ],
)
